#!/usr/bin/env sh
git pull
chmod +x deploy.sh
# 检查 远程package-lock.json 和本地package-lock.json 是否相同
if [ ! -f "package-lock.json" ]; then
  echo "package-lock.json not found. Running npm ci."
  npm ci
  exit 0
fi
npm run build

# 检查端口是否被占用
check_port() {
    local port=$1
    local result=$(netstat -tuln | grep ":$port ")

    if [[ -n "$result" ]]; then
        echo "Port $port is occupied."
        PORT=5001 pm2 reload icar-api
    else
        echo "Port $port is available."
        PORT=5001 pm2 start npm --name "icar-api" -- start
    fi
}

# 使用示例
check_port 5001


# PORT=5001 pm2 start npm --name "nextjs" -- start
# PORT=5001 pm2 reload nextjs




